package com.welsy.newsmgt.business
{
	import mx.rpc.IResponder;
	import mx.rpc.soap.WebService;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import com.adobe.cairngorm.business.ServiceLocator;
	import mx.collections.ArrayCollection;
	import mx.rpc.soap.Operation;
	import com.welsy.util.NamespaceLocator;
	import com.welsy.user.vo.NewsVO;
	
	public class RemoveNewsDelegate
	{
		
		private var responder : IResponder;
		private var service : Object;
		
		public function RemoveNewsDelegate(responder : IResponder) {
			this.responder = responder;
			this.service = ServiceLocator.getInstance().getWebService("NewsService") as WebService;
		}
		
		public function removeNews(news : ArrayCollection) : void {
			var oper : Operation = Operation(WebService(service).getOperation("RemoveNews"));
			var root : String = "<RemoveNews xmlns='http://Welsy.ServiceContracts/2007/02'>";
			root += "<RemoveNewsRequest xmlns='"+NamespaceLocator.NEWS_DATATYPES+"'>";

			var tag_news : String = "<NewsId>";
			for each(var _news : NewsVO in news) {
				tag_news += "<decimal>"+_news.newsId+"</decimal>";
			}	
			tag_news += "</NewsId>";

			root += tag_news;
			root += "</RemoveNewsRequest>";
			root += "</RemoveNews>";
			
			oper.request = new XML(root);

			var token : AsyncToken = service["RemoveNews"].send();
			token.addResponder(responder);
		}
	}
}